<?php


class Zixuncategory extends Base_Controller
{
	
	
	public function __construct()
	{
		parent::__construct();
		$this->load->library('form_validation');
		$this->load->model( 'zixuncategory_mdl', 'zixuncategory' );
		
	}
	
	public function index()
	{
		/*分页设置*/
				
		$data = array();
		$data['list'] = $this->zixuncategory->getZixunCategoryList( false );
		$this->load->view( 'adminroot/zixuncategory', $data );
	}
	
	/**
	 * 
	 * 添加分类
	 */
	
	public function add()
	{
		$this->load->library('form_validation');
		$this->_load_validation_rules();
		
		if ( $this->form_validation->run() == FALSE ){
			
			$this->load->view( 'adminroot/zixuncategory_add' );
			
		} else {
			
			$data['name']     = $this->input->post('name');
			$data['rank']     = $this->input->post('rank');
			
			if ( $this->zixuncategory->addzixuncategory($data) ) {
				
				redirect( 'adminroot/zixuncategory' );
				
			}		
		}
		
	}
	
	public function edit()
	{
		$id = intval( $this->uri->rsegment(4) );
		$category = array();
		$category = $this->zixuncategory->getCategoryById( $id );
	
		
		$data['category'] = $category;
		
		$this->load->view( 'adminroot/zixuncategory_edit', $data );
	}
	
	/**
	 * 更新通告
	 */
	
	public function update()
	{
		
		$this->load->library('form_validation');
		$this->_load_validation_rules();
		
		if ( $this->form_validation->run() == true ) {
			
			$id = $this->input->post("id");
			$data['name']   = $this->input->post( 'name' );
			$data['rank']      = $this->input->post( 'rank' );
			
			$config['id'] = $id;
			
			if ( $this->zixuncategory->zixuncategoryUpdate( $data, $config )) {
				
				redirect( 'adminroot/zixuncategory' );
				
			}
		} 
	}
	
	
	/**
	 * 
	 * 表单验证
	 */
	private function _load_validation_rules()
	{
		$this->form_validation->set_error_delimiters('<li>', '</li>');
		$this->form_validation->set_rules('name','分类名称','required|xss_clean');

	}
}